package ch.fusun.baron.basic.initialization;

import ch.fusun.baron.basic.messages.Messages;
import ch.fusun.baron.core.initialization.GameInitializer;
import ch.fusun.baron.core.injection.Inject;
import ch.fusun.baron.core.rmi.User;
import ch.fusun.baron.core.service.UserService;
import ch.fusun.baron.player.Dynasty;
import ch.fusun.baron.player.api.PlayerService;
import ch.fusun.baron.printing.MessagingService;
import ch.fusun.baron.treasury.api.TreasuryService;

/**
 * Initializes each player with a treasury
 */
public class TreasuryPlayerInitializer implements GameInitializer {

	@Inject
	private TreasuryService treasuryService;
	@Inject
	private UserService userService;
	@Inject
	private PlayerService playerService;
	@Inject
	private MessagingService messagingService;

	/**
	 * Constructor
	 */
	public TreasuryPlayerInitializer() {
	}

	@Override
	public void initialize() {
		for (User user : userService.getUsers()) {
			Dynasty dynasty = playerService.getDynasty(user);
			treasuryService.setMoney(dynasty, 1000);
		}
		messagingService.addMessage(null,
				Messages.TreasuryPlayerInitializer_TreasuryInitialized);
	}
}
